package mvc.core;

import java.lang.reflect.Proxy;

/**
 * 代理工厂生产一个代理实现注解为@Batis的接口
 * 
 * @author liuzy
 * @version 2.0
 * @since 2015年5月14日
 */
public class MapperProxyFactory<T> {

	private final Class<T> mapperInterface;

	public MapperProxyFactory(Class<T> mapperInterface) {
		this.mapperInterface = mapperInterface;
	}

	@SuppressWarnings("unchecked")
	public T newInstance() {
		final MapperProxy<T> mapperProxy = new MapperProxy<T>();
		return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[] { mapperInterface }, mapperProxy);
	}

	protected Class<T> getMapperInterface() {
		return mapperInterface;
	}

}